package com.dev.sacot41.myresume;

import com.dev.sacot41.scviewpager.DotsView;
import com.dev.sacot41.scviewpager.SCPositionAnimation;
import com.dev.sacot41.scviewpager.SCViewAnimation;
import com.dev.sacot41.scviewpager.SCViewAnimationUtil;
import com.dev.sacot41.scviewpager.SCViewPager;
import com.dev.sacot41.scviewpager.SCViewPagerProvider;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.PageSlider;

public class MainAbility extends Ability {

    private static final int NUM_PAGES = 5;
    private SCViewPager mViewPager;
    private SCViewPagerProvider mPageProvider;
    private DotsView mDotsView;
    private int screenWidth;
    private int screeHeigth;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_ability_main);

        mViewPager = (SCViewPager) findComponentById(ResourceTable.Id_viewpager_main_ability);
        mDotsView = (DotsView) findComponentById(ResourceTable.Id_dotsview_main);
        mDotsView.setDotRessource(ResourceTable.Media_dot_selected, ResourceTable.Media_dot_unselected);
        mDotsView.setNumberOfPage(NUM_PAGES);

        mPageProvider = new SCViewPagerProvider(this);
        mPageProvider.setNumberOfPage(NUM_PAGES);
        mPageProvider.setFragmentBackgroundColor(0xCFD8DCFF);
        mViewPager.setProvider(mPageProvider);

        mViewPager.addPageChangedListener(new PageSlider.PageChangedListener() {
            @Override
            public void onPageSliding(int i, float v, int i1) {
            }

            @Override
            public void onPageSlideStateChanged(int state) {
            }

            @Override
            public void onPageChosen(int position) {
                mDotsView.selectDot(position);
            }
        });

        screenWidth = SCViewAnimationUtil.getDisplaySize(this).getPointXToInt();
        screeHeigth = SCViewAnimationUtil.getDisplaySize(this).getPointYToInt();

        Component nameTag = findComponentById(ResourceTable.Id_iv_name_tag);
        SCViewAnimation nameTagAnimation = new SCViewAnimation(nameTag);
        nameTagAnimation.addPageAnimation(new SCPositionAnimation(0, 0, -screeHeigth / 2));
        mViewPager.addAnimation(nameTagAnimation);

        Component currentlyWork = findComponentById(ResourceTable.Id_iv_currently_work);
        SCViewAnimation currentlyWorkAnimation = new SCViewAnimation(currentlyWork);
        currentlyWorkAnimation.addPageAnimation(new SCPositionAnimation(0, -screenWidth, 0));
        mViewPager.addAnimation(currentlyWorkAnimation);

        Component atSkex = findComponentById(ResourceTable.Id_iv_at_skex);
        SCViewAnimation atSkexAnimation = new SCViewAnimation(atSkex);
        atSkexAnimation.addPageAnimation(new SCPositionAnimation(0, 0, -(screeHeigth)));
        mViewPager.addAnimation(atSkexAnimation);

        getContext().getUITaskDispatcher().delayDispatch(new Runnable() {
            @Override
            public void run() {
                initDelay();
            }
        }, 50);

    }

    private void initDelay() {
        Component commonlyView = findComponentById(ResourceTable.Id_iv_commonly);
        SCViewAnimation commonlyAnimation = new SCViewAnimation(commonlyView);
        commonlyAnimation.startToPosition(screenWidth, null);
        commonlyAnimation.addPageAnimation(new SCPositionAnimation(0, -screenWidth, 0));
        commonlyAnimation.addPageAnimation(new SCPositionAnimation(1, -screenWidth, 0));
        mViewPager.addAnimation(commonlyAnimation);

        Component djangoView = findComponentById(ResourceTable.Id_iv_django_python);
        SCViewAnimation djangoAnimation = new SCViewAnimation(djangoView);
        djangoAnimation.startToPosition(null, -screeHeigth);
        djangoAnimation.addPageAnimation(new SCPositionAnimation(0, 0, screeHeigth));
        djangoAnimation.addPageAnimation(new SCPositionAnimation(1, 0, screeHeigth));
        mViewPager.addAnimation(djangoAnimation);

        Component mobileView = findComponentById(ResourceTable.Id_iv_mobile);
        SCViewAnimation mobileAnimation = new SCViewAnimation(mobileView);
        mobileAnimation.startToPosition((int) (screenWidth * 1.5), null);
        mobileAnimation.addPageAnimation(new SCPositionAnimation(0, -(int) (screenWidth * 1.5), 0));
        mobileAnimation.addPageAnimation(new SCPositionAnimation(1, -(int) (screenWidth * 1.5), 0));
        mViewPager.addAnimation(mobileAnimation);

        Component butView = findComponentById(ResourceTable.Id_iv_but);
        SCViewAnimation butAnimation = new SCViewAnimation(butView);
        butAnimation.startToPosition(screenWidth, null);
        butAnimation.addPageAnimation(new SCPositionAnimation(1, -screenWidth, 0));
        butAnimation.addPageAnimation(new SCPositionAnimation(2, -screenWidth, 0));
        mViewPager.addAnimation(butAnimation);

        Component diplomeView = findComponentById(ResourceTable.Id_iv_diploma);
        SCViewAnimation diplomeAnimation = new SCViewAnimation(diplomeView);
        diplomeAnimation.startToPosition((screenWidth * 2), null);
        diplomeAnimation.addPageAnimation(new SCPositionAnimation(1, -screenWidth * 2, 0));
        diplomeAnimation.addPageAnimation(new SCPositionAnimation(2, -screenWidth * 2, 0));
        mViewPager.addAnimation(diplomeAnimation);

        Component whyView = findComponentById(ResourceTable.Id_iv_why);
        SCViewAnimation whyAnimation = new SCViewAnimation(whyView);
        whyAnimation.startToPosition(screenWidth, null);
        whyAnimation.addPageAnimation(new SCPositionAnimation(1, -screenWidth, 0));
        whyAnimation.addPageAnimation(new SCPositionAnimation(2, -screenWidth, 0));
        mViewPager.addAnimation(whyAnimation);

        Component futureView = findComponentById(ResourceTable.Id_iv_future);
        SCViewAnimation futureAnimation = new SCViewAnimation(futureView);
        futureAnimation.startToPosition(null, -screeHeigth);
        futureAnimation.addPageAnimation(new SCPositionAnimation(2, 0, screeHeigth));
        futureAnimation.addPageAnimation(new SCPositionAnimation(3, -screenWidth, 0));
        mViewPager.addAnimation(futureAnimation);

        Component arduinoView = findComponentById(ResourceTable.Id_iv_arduino);
        SCViewAnimation arduinoAnimation = new SCViewAnimation(arduinoView);
        arduinoAnimation.startToPosition(screenWidth * 2, null);
        arduinoAnimation.addPageAnimation(new SCPositionAnimation(2, -screenWidth * 2, 0));
        arduinoAnimation.addPageAnimation(new SCPositionAnimation(3, -screenWidth, 0));
        mViewPager.addAnimation(arduinoAnimation);

        Component raspberryView = findComponentById(ResourceTable.Id_iv_raspberry_pi);
        SCViewAnimation raspberryAnimation = new SCViewAnimation(raspberryView);
        raspberryAnimation.startToPosition(-screenWidth, null);
        raspberryAnimation.addPageAnimation(new SCPositionAnimation(2, screenWidth, 0));
        raspberryAnimation.addPageAnimation(new SCPositionAnimation(3, -screenWidth, 0));
        mViewPager.addAnimation(raspberryAnimation);

        Component connectedDeviceView = findComponentById(ResourceTable.Id_iv_connect_device);
        SCViewAnimation connectedDeviceAnimation = new SCViewAnimation(connectedDeviceView);
        connectedDeviceAnimation.startToPosition((int) (screenWidth * 1.5), null);
        connectedDeviceAnimation.addPageAnimation(new SCPositionAnimation(2, -(int) (screenWidth * 1.5), 0));
        connectedDeviceAnimation.addPageAnimation(new SCPositionAnimation(3, -screenWidth, 0));
        mViewPager.addAnimation(connectedDeviceAnimation);

        Component checkOutView = findComponentById(ResourceTable.Id_iv_check_out);
        SCViewAnimation checkOutAnimation = new SCViewAnimation(checkOutView);
        checkOutAnimation.startToPosition(screenWidth, null);
        checkOutAnimation.addPageAnimation(new SCPositionAnimation(3, -screenWidth, 0));
        mViewPager.addAnimation(checkOutAnimation);

        Component linkedinView = findComponentById(ResourceTable.Id_tv_link);
        SCViewAnimation linkedinAnimation = new SCViewAnimation(linkedinView);
        linkedinAnimation.startToPosition(screenWidth, null);
        linkedinAnimation.addPageAnimation(new SCPositionAnimation(3, -screenWidth, 0));
        mViewPager.addAnimation(linkedinAnimation);
    }

}
